// pages/shop/erji//goodsInfo/goodsInfo.js
var base = require('../../../../base.js');  //路径可能做相应调整
const _ = base._; //翻译函数
const { HTTP } = require('../../../../lib/http.js')
const { URL } = require('../../../../lib/urls.js')
const { getUserToken, getUserInfo } = require('../../../../lib/user.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    _t: [],
    goodsModel:null,
    isCn:true,
    itemList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      _t: base._t(), //翻译
    });
    var model = JSON.parse(options.data);
    this.setData({
      goodsModel:model,
      isCn:(wx.getStorageSync('Language') || 'cn') == 'en' ? false : true,
      itemList: JSON.parse(model.Detail),
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  //添加到购物车
  addCartTap: function () {
    var that = this;
    HTTP({
      url: URL.goods.changeCart,
      userToken: getUserToken(),
      data: {
        ProductCode: that.data.goodsModel.ProductCode,
        Count: 1,
        MemberId: getUserInfo().memberId,
        IsAdd:true,
      },
      success: (res) => {
        wx.showToast({
          title: _('添加成功'),
        })
      },
      fail: (res) => {
        console.log(res)
        wx.showToast({
          title: res.msg,
          icon: 'none'
        })
      }
    })
  },
})